package com.zj.seckill.service;

import com.zj.seckill.dao.GoodsDao;
import com.zj.seckill.domain.Goods;
import com.zj.seckill.domain.MiaoshaGoods;
import com.zj.seckill.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhouji
 * @create 2021/4/8
 */

@Service
@Transactional
public class GoodsService {

    @Autowired
    GoodsDao goodsDao;

    public List<GoodsVo> listGoodsVo(){
        List<GoodsVo> goodsVoList = goodsDao.listGoodsVo();
        return goodsVoList;
    }

    public GoodsVo getGoodsVoByGoodsId(long goodsId) {

        return goodsDao.getGoodsVoByGoodsId(goodsId);
    }

    public boolean reduceStock(GoodsVo goods) {
        MiaoshaGoods goods1 = new MiaoshaGoods();
        goods1.setGoodsId(goods.getId());
        int ret = goodsDao.reduceStock(goods1);
        return ret>0;
    }
}
